﻿using System;
using System.IO;
using System.Net;
using System.Threading;

namespace Jimmy.Helper
{
    public class LogHelper
    {
        protected static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(typeof(LogHelper));

        static LogHelper()
        {
            string log4netConfigSource = System.Configuration.ConfigurationManager.AppSettings["log4netConfigSource"];
            if (log4netConfigSource == null)
            {
                return;
            }
            string filename = "";
            if (!string.IsNullOrEmpty(log4netConfigSource))
            {
                filename = Path.Combine(FileHelper.GetAppBasePath(), log4netConfigSource);
                log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(filename));
            }
            else
                throw new Exception("应用系统日志配置文件配置错误！");
        }
        public static void Error(string msg)
        {
            try
            {
                Logger.Error(msg);
            }
            catch
            {
            }
        }
        public static void Error(string msg, Exception ex)
        {
            try
            {
                Logger.Error(msg, ex);
            }
            catch { }
        }
        public static void Error(LogMessage msg, Exception ex)
        {
            try
            {
                Logger.Error(msg, ex);
            }
            catch { }
        }
        public static void Info(string msg)
        {
            try
            {
                Logger.Info(msg);
            }
            catch { }
        }
        public static void Info(string msg, Exception ex)
        {
            try
            {
                Logger.Info(msg, ex);
            }
            catch { }
        }
        public static void Info(LogMessage msg, Exception ex)
        {
            try
            {
                Logger.Info(msg, ex);
            }
            catch { }
        }
        public static void Warn(string msg)
        {
            try
            {
                Logger.Warn(msg);
            }
            catch { }
        }
        public static void Warn(string msg, Exception ex)
        {
            try
            {
                Logger.Warn(msg, ex);
            }
            catch { }
        }
        public static void Warn(LogMessage msg, Exception ex)
        {
            try
            {
                Logger.Warn(msg, ex);
            }
            catch { }
        }
        public static void Debug(string msg)
        {
            try
            {
                Logger.Debug(msg);
            }
            catch { }
        }
        public static void Debug(string msg, Exception ex)
        {
            try
            {
                Logger.Debug(msg, ex);
            }
            catch { }
        }
        public static void Debug(LogMessage msg, Exception ex)
        {
            try
            {
                Logger.Debug(msg, ex);
            }
            catch { }
        }
    }
}
